import networkx as nx
import matplotlib.pyplot as plt

from bean import Library, Point


def initPoint() -> list:
    pointList = list()
    pointList.append(Point(0, 2, 30, 150, 20))
    pointList.append(Point(1, 3, 20, 80, 20))
    pointList.append(Point(2, 2.5, 20, 140, 25))
    pointList.append(Point(4, 2, 20, 80, 15))
    pointList.append(Point(5, 2, 50, 170, 15))
    pointList.append(Point(6, 3, 50, 170, 20))
    pointList.append(Point(7, 2.5, 60, 180, 25))
    pointList.append(Point(9, 3, 60, 180, 30))
    pointList.append(Point(10, 1.5, 50, 170, 25))
    pointList.append(Point(11, 2, 40, 160, 20))
    pointList.append(Point(12, 1.5, 30, 270, 20))
    pointList.append(Point(13, 2, 20, 140, 25))
    pointList.append(Point(14, 3, 40, 280, 30))
    pointList.append(Point(15, 3, 30, 150, 25))
    pointList.append(Point(16, 2, 20, 140, 20))
    pointList.append(Point(17, 2, 40, 160, 20))
    pointList.append(Point(18, 1.5, 30, 150, 25))
    pointList.append(Point(20, 2, 60, 120, 25))
    pointList.append(Point(21, 2.5, 30, 150, 20))
    pointList.append(Point(22, 2, 20, 140, 15))
    pointList.append(Point(23, 2, 40, 160, 15))
    pointList.append(Point(24, 1.5, 30, 270, 20))
    pointList.append(Point(25, 2, 20, 140, 25))
    pointList.append(Point(26, 3, 30, 150, 20))
    pointList.append(Point(29, 2, 20, 140, 20))
    pointList.append(Point(30, 2.5, 40, 160, 20))
    pointList.append(Point(31, 1.5, 30, 150, 25))
    pointList.append(Point(32, 3, 30, 270, 30))
    pointList.append(Point(33, 3, 60, 120, 25))
    return pointList


def initLibrary() -> list:
    libraryList = list()
    libraryList.append(Library(3, 20, 6, 20))
    libraryList.append(Library(8, 25, 6.5, 18))
    libraryList.append(Library(19, 30, 8, 15))
    libraryList.append(Library(27, 20, 6, 16))
    libraryList.append(Library(28, 20, 6, 22))

    return libraryList


def initEdge() -> list:
    edgeList = list()
    edgeList.extend([{'startP': 0, 'endP': 1, 'length': 25, 'v': 30},
                     {'startP': 1, 'endP': 2, 'length': 17, 'v': 50},
                     {'startP': 2, 'endP': 3, 'length': 32, 'v': 60},
                     {'startP': 3, 'endP': 4, 'length': 5.8, 'v': 60},
                     {'startP': 3, 'endP': 5, 'length': 37, 'v': 50},
                     {'startP': 5, 'endP': 6, 'length': 29, 'v': 50},
                     {'startP': 6, 'endP': 7, 'length': 10, 'v': 30},
                     {'startP': 7, 'endP': 8, 'length': 31, 'v': 40},
                     {'startP': 8, 'endP': 9, 'length': 17, 'v': 40},
                     {'startP': 8, 'endP': 10, 'length': 10, 'v': 20},
                     {'startP': 9, 'endP': 11, 'length': 4.8, 'v': 20},
                     {'startP': 10, 'endP': 13, 'length': 3, 'v': 20},
                     {'startP': 10, 'endP': 12, 'length': 8, 'v': 20},
                     {'startP': 11, 'endP': 14, 'length': 13, 'v': 20},
                     {'startP': 12, 'endP': 15, 'length': 20, 'v': 30},
                     {'startP': 15, 'endP': 16, 'length': 5, 'v': 20},
                     {'startP': 16, 'endP': 18, 'length': 23, 'v': 40},
                     {'startP': 16, 'endP': 17, 'length': 36, 'v': 50},
                     {'startP': 17, 'endP': 19, 'length': 10, 'v': 30},
                     {'startP': 19, 'endP': 21, 'length': 5, 'v': 20},
                     {'startP': 19, 'endP': 20, 'length': 8, 'v': 20},
                     {'startP': 20, 'endP': 22, 'length': 10, 'v': 30},
                     {'startP': 21, 'endP': 23, 'length': 2, 'v': 20},
                     {'startP': 21, 'endP': 24, 'length': 16, 'v': 40},
                     {'startP': 21, 'endP': 23, 'length': 5, 'v': 20},
                     {'startP': 23, 'endP': 26, 'length': 2, 'v': 20},
                     {'startP': 23, 'endP': 25, 'length': 23, 'v': 40},
                     {'startP': 25, 'endP': 27, 'length': 26, 'v': 30},
                     {'startP': 26, 'endP': 28, 'length': 13, 'v': 20},
                     {'startP': 27, 'endP': 34, 'length': 8, 'v': 20},
                     {'startP': 27, 'endP': 29, 'length': 2, 'v': 20},
                     {'startP': 27, 'endP': 30, 'length': 8, 'v': 20},
                     {'startP': 28, 'endP': 31, 'length': 3, 'v': 20},
                     {'startP': 29, 'endP': 32, 'length': 4, 'v': 20},
                     {'startP': 31, 'endP': 33, 'length': 5, 'v': 20}])
    return edgeList


def initGraph() -> nx.Graph:
    # 创建一个空的无向有权图
    G = nx.Graph()

    # 添加节点
    for i in range(0, 34):
        G.add_node(i)

    # 添加边及权重
    edgeList = initEdge()
    for e in edgeList:
        G.add_edge(e['startP'], e['endP'], weight=round(e['length'] / e['v'] * 60, 2))

        # G.add_edge(0, 1, weight=50)
        # G.add_edge(1, 2, weight=20.4)
        # G.add_edge(2, 3, weight=32)
        # G.add_edge(3, 4, weight=8.7)
        # G.add_edge(3, 5, weight=44.4)
        # G.add_edge(5, 6, weight=34.8)
        # G.add_edge(6, 7, weight=20)
        # G.add_edge(7, 8, weight=46.5)
        # G.add_edge(8, 9, weight=25.5)
        # G.add_edge(9, 11, weight=14.4)
        # G.add_edge(11, 14, weight=39)
        # G.add_edge(8, 10, weight=30)
        # G.add_edge(10, 13, weight=9)
        # G.add_edge(10, 12, weight=24)
        # G.add_edge(12, 15, weight=40)
        # G.add_edge(15, 16, weight=15)
        # G.add_edge(16, 18, weight=34.5)
        # G.add_edge(16, 17, weight=43.2)
        # G.add_edge(17, 19, weight=20)
        # G.add_edge(19, 21, weight=15)
        # G.add_edge(19, 20, weight=24)
        # G.add_edge(20, 22, weight=20)
        # G.add_edge(21, 23, weight=6)
        # G.add_edge(21, 24, weight=24)
        # G.add_edge(23, 26, weight=6)
        # G.add_edge(23, 25, weight=34.5)
        # G.add_edge(25, 27, weight=52)
        # G.add_edge(26, 28, weight=39)
        # G.add_edge(27, 30, weight=24)
        # G.add_edge(27, 29, weight=6)
        # G.add_edge(28, 31, weight=9)
        # G.add_edge(29, 32, weight=12)
        # G.add_edge(31, 33, weight=15)

    return G
